WOLF core
WOLF: A Modular Estimation Framework for Robotics
XXXXXXXXXXXXXXXXXXXXXXXXvoid(0)" frameborder="0" name="MSearchResults" id="MSearchResults">
singleton.h
Go to the documentation of this file.
1// WOLF - Copyright (C) 2020-2026
2// Institut de Robòtica i Informàtica Industrial, CSIC-UPC.
3// Authors: Joan Solà Ortega (jsola@iri.upc.edu) and
4// Joan Vallvé Navarro (jvallve@iri.upc.edu)
5// All rights reserved.
6//
7// This file is part of WOLF: http://www.iri.upc.edu/wolf
8// WOLF is free software: you can redistribute it and/or modify
9// it under the terms of the GNU General Public License version 3
10// as published by the Free Software Foundation.
11//
12// This program is distributed in the hope that it will be useful,
13// but WITHOUT ANY WARRANTY; without even the implied warranty of
14// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15// GNU General Public License for more details.
16//
17// You should have received a copy of the GNU General Public License
18// along with this program. If not, see <http://www.gnu.org/licenses/>.
19#pragma once
20
21#include <memory>
22
23namespace wolf
24{
25namespace internal
26{
31template <class T>
33{
34 using SingletonOPtr = std::unique_ptr<T>;
35
36 public:
39 template <typename... Args>
40 static T& get(Args&&... args)
41 {
42 static SingletonOPtr instance_(new T(std::forward<Args>(args)...));
43
44 return *instance_;
45 }
46
49 constexpr Singleton(const Singleton&) = delete;
50
53 constexpr Singleton(const Singleton&&) = delete;
54
57 constexpr Singleton& operator=(const Singleton&) const = delete;
58
61 constexpr Singleton& operator=(const Singleton&&) const = delete;
62
63 protected:
66 constexpr Singleton() = default;
67
70 virtual ~Singleton() = default;
71};
72
73} // namespace internal
74} // namespace wolf
A thread-safer (?) Singleton implementation with argument forwarding.
Definition: singleton.h:33
constexpr Singleton & operator=(const Singleton &) const =delete
Copy assignment (deleted)
constexpr Singleton(const Singleton &)=delete
Copy constructor (deleted)
constexpr Singleton & operator=(const Singleton &&) const =delete
Move assignment (deleted)
static T & get(Args &&... args)
Returns the singleton instance, created the first time with the arguments.
Definition: singleton.h:40
constexpr Singleton(const Singleton &&)=delete
Move constructor (deleted)
constexpr Singleton()=default
Default constructor (protected)
virtual ~Singleton()=default
Destructor.
Definition: capture_base.h:23